<style>
  .BalanceDetail {
    padding-bottom: 0.98rem;
    box-sizing: border-box;
  }
  .BalanceNumericalBtn{position: absolute;top:0;right:0;margin-top:-10px;}
</style>
<div class="CenterHeaderBox RollingGoal">
  <div class="CenterBackBtn">
    <a href="javascript:history.go(-1)"
      ><img src="__CDN__/map/images/return.png" alt="返回"
    /></a>
  </div>
  <div class="CenterHeaderTitle">我的余额</div>
</div>

<div class="CenterMain">
  <div class="BalanceTop gradualBg">
    <div class="BalanceNumerical am-cf">
      <div class="BalanceNum am-fl">
        <p class="p1">我的余额</p>
        <p class="p2">{$user.money}</p>
      </div>
      <!--<div class="BalanceTi am-fl">-->
        <!--<p class="p1">可提余额</p>-->
        <!--<p class="p2">{$mentioning}</p>-->
      <!--</div>-->
      <div class="BalanceNumericalBtn">
        <a href="{:url('user/tempted')}">提现</a>
      </div>
    </div>
  </div>
  <div class="BalanceList">
    <div class="title">余额明细</div>
    <div
      class="BalanceDetail"
      style="position: absolute;width:100%;height: 140%;overflow-y:auto;-webkit-overflow-scrolling: touch;"
    >
      <ul id="ul"></ul>
    </div>
  </div>
</div>
<script type="text/javascript" src="__CDN__/assets/js/zepto.min.js"></script>
<script
  type="text/javascript"
  src="__CDN__/assets/js/PullToRefresh.min.js"
></script>
<script>
  var n = 0,
    flag = true;

  var refreshBox = new PullToRefresh({
    container: ".BalanceDetail",
    // pull: {
    //   callback: function() {
    //     setTimeout(function() {
    //       n = 0;
    //       re_ajax(n);
    //       refreshBox.endPullRefresh(true);
    //     }, 1000);
    //   }
    // },
    up: {
      callback: function() {
        setTimeout(function() {
          n++;
          re_ajax(n);
          refreshBox.endUpLoading(flag);
        }, 1000);
      }
    }
  });
  function re_ajax(page) {
    $.ajax({
      type: "GET",
      url: "{$http_url}/index/user/balance",
      dataType: "json",
      data: {
        page: page
      },
      success: function(data) {
        if (page == 1 || page == 0) {
          $("#ul").html("");
        }
        var html = "";
        data.data.forEach(function(v) {
            var string_str='';
            var str_name='';
          if (v.money_type == 9) {
            html += '<li class="am-cf">';
            html += '<div class="textL am-fl">';
            html += '  <p class="p1"><span>消费</span> </p> ';
            html += '  <p class="p2">' + v.createtime + "</p>";
            html += "</div>";
            html += '<div class="textR am-fr">-' + v.money + "</div>";
            html += "</li>";
          } else {
            var name = "";
            if (v.money_type == 1) {
              name = "二级个权分润";
                str_name='来源会员ID:'+v.playUser_id;
            } else if (v.money_type == 2) {
                str_name='来源会员ID:'+v.playUser_id;
              name = "商家分润";
            } else if (v.money_type == 3) {
                str_name='来源会员ID:'+v.playUser_id;
                name='服务商分润';
                // var server={$user.server_type};
                // if(server==1){
                //     name='服务商';
                // }else if(server==2){
                //     name='市代理';
                // }else if(server==3){
                //     name='区代理';
                // }
            }  else if (v.money_type == 4) {
                string_str="+";
              name = "分红奖励";
            } else if (v.money_type == 5) {
                string_str="+";
              name = "股权奖励";
            } else if (v.money_type == 7) {
                string_str="-";
                 name = "提现";
                str_name=v.status;
            } else if (v.money_type == 9) {
                str_name='来源会员ID:'+v.playUser_id;
              name = "消费余额";
                string_str="-";
            }else if (v.money_type == 8) {
                if(v.user_id==v.playUser_id){
                    str_name='来源会员ID:'+v.playUser_id;
                    string_str="+";
                    name = "二级贡献值";
                }else{
                    str_name='会员ID:'+v.user_id;
                    name = "消费贡献值";
                    string_str="+";
                }

            } else if (v.money_type == 10) {
                str_name='来源会员ID:'+v.playUser_id;
                string_str="+";
              name = "商家应收款";
            } else if (v.money_type == 11) {
                str_name='来源会员ID:'+v.playUser_id;
                string_str="+";
                name = "二级个权分佣";
            }else if (v.money_type == 13) {
                str_name='来源会员ID:'+v.playUser_id;
                string_str="+";
                name = "跨商家收益";
            }
            html += '<li class="am-cf">';
            html += '<div class="textL am-fl">';
            html +=
              '  <p class="p1"><span>' +
              name +
              "</span> " + str_name+
              "</p> ";
            html += '  <p class="p2">' + v.createtime + "</p>";
            html += "</div>";
            html += '<div class="textR dmColor am-fr">' +string_str+ v.money + "</div>";
            html += "</li>";
          }
        });
        // $("#ul")[type](html)
        $("#ul").append(html);
        if (html == "") {
          flag = false;
        }
      },
      error: function(jqXHR) {
        console.log("Error: " + jqXHR.status);
      }
    });
  }
</script>
